package im.ok.back.service.impl;

import im.ok.back.common.ServerResponse;
import im.ok.back.dao.UserMapper;
import im.ok.back.pojo.User;
import im.ok.back.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public ServerResponse<User> login(Integer userId, String password) {
        int count = userMapper.countByUserId(userId);
        if (count == 0) {
            return ServerResponse.createError("账号不存在！");
        }

        User user = userMapper.selectLoginInfo(userId, password);
        if (user == null) {
            return ServerResponse.createError("密码错误！");
        }
        user.setPassword(StringUtils.EMPTY);
        return ServerResponse.createSuccessData("登录成功！", user);
    }
}
